package com.uyaer.wheel.display.scene.el
{
	import com.uyaer.wheel.common.Common;
	import com.uyaer.wheel.res.ResManager;
	import com.uyaer.wheel.utils.Utils;
	
	public class Cloud extends ElementBase
	{
		private var moveIndex:int = 0 ;
		private var moveCount:int = 0 ;
		private var speedX:Number = -0.3;
		private var speedY:Number = -1;
		private var rangMin:int = 100;
		private var rangMax:int = 300;
		public function Cloud()
		{
			super(ResManager.me.getTextures("home_cloud"+(Utils.rangInt(1,2))),1);
			this.stop();
			this.init();
		}
		
		override internal function init():void{
			moveCount = Utils.rangInt(rangMin, rangMax);
			moveIndex = 0;	
			speedX = Math.random()<0.5?-0.5:0.5;
			speedY = -1.5 - Utils.rangInt(0,10)/10.0;
			speedX *= Common.S;
			speedY *= Common.S;
			this.x = this.y = 0;
		}
		
		override public function move():void{
			moveIndex ++;
			if(moveIndex >= moveCount){
				reverseSpeed();
			}
			this.x += speedX;
			this.y += speedY;
			
			if(this.x <=0 || this.x >= Common.W){
				this.reverseSpeed();
			}
		}
		
		private function reverseSpeed():void{
			moveIndex = 0 ;
			moveCount = Utils.rangInt(rangMin, rangMax);
			speedX *= -1;
		}
		
		override public function recycle():void{
			super.recycle();
			ElPool.recycleCloud(this);
		}
		
		
	}
}